<?php
##############################################
#
#   地区
# @ Time : 2017-1-8 - 下午6:16:20
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;

class LocalityModel extends AdminBaseModel{
	/*地区表  */
	protected $tableName = 'locality';	
	
	public function __construct($tableName=''){
		//初始化数据库对象
		if(!empty($tableName)){
			$this -> tableName = $tableName;
		}	
		parent::__construct($this -> tableName);
	}
	
	/**
	 * 获取分类
	 */
	public function getLocality(){
		return $this ->order('sort asc') -> select();
	}
	
	/**
	 * 处理分类数据
	 * @param array $category
	 * @return array
	 */
	public function disData($locality){
		return Data::channel($locality, 'lid', 'pid', 0, 0, 2,'&nbsp;&nbsp;&nbsp;&nbsp');
	}
	
	/**
	* 删除地区
	* @param int $cid
	*/
	public function deleteLocality($lid){
	//判断是否有父级地区存在
		$data = $this -> where("pid = $lid") ->find();
		if(count($data) > 0){
			return 1;
		}else{
			$result = $this -> where("lid = $lid") -> delete();
		if($result)
			return 2;
		else
			return 3;
		}
	}
	
}